﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace BooksManagermentSystem
{
    public partial class DeleteBookType_form : Form
    {
        public DeleteBookType_form()
        {
            InitializeComponent();
        }

        private void DeleteBookType_form_Load(object sender, EventArgs e)
        {
            ShowAllBookType();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string typename = comboBox1.Text;

            DialogResult rt = MessageBox.Show($"确定要删除【{typename}】吗？", "提示", MessageBoxButtons.YesNo);
            if (rt == DialogResult.Yes)
            {
                string sql = $"delete from BookType where typename= '{typename}'";
                if (DBhelper.NonQuery(sql))
                {
                    MessageBox.Show("删除成功");
                    ShowAllBookType();
                }
                else
                {
                    MessageBox.Show("修改失败！");
                }
            }
        }

        private void ShowAllBookType()
        {
            string sql = "select * from BookType";
            DataTable dt = DBhelper.GetDataTable(sql);
            comboBox1.DataSource = dt;
            comboBox1.DisplayMember = "typename";
        }
    }
}
